package easycloud.ecs.common.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.springframework.data.jpa.domain.AbstractPersistable;

import easycloud.ecs.common.domain.Provider.PROVIDER_TYPE;

@SuppressWarnings("serial")
@MappedSuperclass
public abstract class AbstractProvider extends AbstractPersistable<Integer> {

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "userid")
	private User user;

	@Basic
	@Enumerated(EnumType.STRING)
	@Column(name = "providerType", nullable = false)
	private PROVIDER_TYPE providerType;

	@Column(name = "name", nullable = false)
	private String name;

	@Column(name = "bucketName")
	private String bucketName;

	@Column(name = "accessKey")
	private String accessKey;

	@Column(name = "secretKey")
	private String secretKey;

	@Column(name = "className")
	private String className;

	@Column(name = "createTime", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date createTime;

	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, mappedBy = "provider")
	private Set<Sync> syncs = new HashSet<Sync>();

	public String getAccessKey() {
		return accessKey;
	}

	public String getBucketName() {
		return bucketName;
	}

	public String getClassName() {
		return className;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public String getName() {
		return name;
	}

	public PROVIDER_TYPE getProviderType() {
		return providerType;
	}

	public String getSecretKey() {
		return secretKey;
	}

	public Set<Sync> getSyncs() {
		return syncs;
	}

	public User getUser() {
		return user;
	}

	public void setAccessKey(String accessKey) {
		this.accessKey = accessKey;
	}

	public void setBucketName(String bucketName) {
		this.bucketName = bucketName;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setProviderType(PROVIDER_TYPE providerType) {
		this.providerType = providerType;
	}

	public void setSecretKey(String secretKey) {
		this.secretKey = secretKey;
	}

	public void setSyncs(Set<Sync> syncs) {
		this.syncs = syncs;
	}

	public void setUser(User user) {
		this.user = user;
	}
}
